package com.shu.mq.dxl;

import com.rabbitmq.client.*;
import com.shu.mq.ConnectionUtils;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeoutException;

/**
 * @author ssm
 * @version V1.0
 * @description:
 * @date 2020/9/14 14:19
 */

// 消费者
public class Consumer {

    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = ConnectionUtils.getConnection();
        Channel channel = connection.createChannel();
        String queueName = "test_dlx_queue";

        DefaultConsumer defaultConsumer = new DefaultConsumer(channel) {
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("消费者收到消息：" + new String(body));
//                channel.basicAck(envelope.getDeliveryTag(), false);
                channel.basicReject(envelope.getDeliveryTag(), false);
            }
        };
        channel.basicConsume(queueName, false, defaultConsumer);
    }
}